using System;
using System.Configuration;

namespace OrbitOne.Elmah.Agent
{
    public class AgentConfiguration : ConfigurationSection
    {
        /* if something where to change here. Do not forget to make the changes to the installer. */

        #region Properties

        [ConfigurationProperty("AgentName", IsRequired = false)]
        public string AgentName
        {
            get { return this["AgentName"].ToString(); }
            set { this["AgentName"] = value; }
        }

        [ConfigurationProperty("AgentDescription", IsRequired = false)]
        public string AgentDescription
        {
            get { return this["AgentDescription"].ToString(); }
            set { this["AgentDescription"] = value; }
        }

        [ConfigurationProperty("AgentCreatedOn", IsRequired = true)]
        public DateTime AgentCreatedOn
        {
            get { return (DateTime)this["AgentCreatedOn"]; }
            set { this["AgentCreatedOn"] = value; }
        }

        [ConfigurationProperty("ErrorXmlSourceFolder", IsRequired = true)]
        public string ErrorXmlSourceFolder
        {
            get { return this["ErrorXmlSourceFolder"].ToString(); }
            set { this["ErrorXmlSourceFolder"] = value; }
        }

        [ConfigurationProperty("ErrorXmlFileFilter", IsRequired = false, DefaultValue = "*.xml")]
        public string ErrorXmlFileFilter
        {
            get { return this["ErrorXmlFileFilter"].ToString(); }
            set { this["ErrorXmlFileFilter"] = value; }
        }

        [ConfigurationProperty("InvalidLogFileFolder", IsRequired = true)]
        public string InvalidLogFileFolder
        {
            get { return this["InvalidLogFileFolder"].ToString(); }
            set { this["InvalidLogFileFolder"] = value; }
        }

        [ConfigurationProperty("ElmahWebServiceUrl", IsRequired = true)]
        public string ElmahWebServiceUrl
        {
            get { return this["ElmahWebServiceUrl"].ToString(); }
            set { this["ElmahWebServiceUrl"] = value; }
        }
        #endregion

        #region Constructor

        public AgentConfiguration(DateTime agentCreatedOn, string agentName, string agentDescription, string errorXmlSourceFolder, string errorXmlFileFilter, string invalidLogFileFolder, string elmahWebServiceUrl)
        {
            this.AgentCreatedOn = agentCreatedOn;
            this.AgentName = agentName;
            this.AgentDescription = agentDescription;
            this.ErrorXmlSourceFolder = errorXmlSourceFolder;
            this.ErrorXmlFileFilter = errorXmlFileFilter;
            this.InvalidLogFileFolder = invalidLogFileFolder;
            this.ElmahWebServiceUrl = elmahWebServiceUrl;
        }

        public AgentConfiguration() { }

        #endregion

        #region Static Methods

        public static AgentConfiguration Load()
        {
            return (AgentConfiguration)ConfigurationManager.GetSection("AgentConfiguration");
        }

        #endregion
    }
}

